<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<%@ taglib uri="/permission" prefix="pe" %>

<jsp:include page="../../include/top.jsp"/>
<script src="${BasePath}/js/querycombo.js" type="text/javascript"></script>
<div class="main_body">
    <div class="span9 page_message">
        <section id="contents">
            <ul class="tab-nav nav">
                <li class="current"><a href="">订单列表<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:toAdd()">订单添加/修改<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:multiDel();void(0);">删除<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:orderChecked();void(0);">已到检<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:orderReport();void(0);">报告已回<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:printBarcode();void(0);">打印条码<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:toExtend();void(0);">批量延期<span class="arrow fa fa-sort-up"></span></a></li>
            </ul>
            <p class="normal_tips" style="display:none"><b class="fa fa-info-circle"></b></p>

            <div class="table-bar">
                <div class="fl">
                    <%--<div class="tools">--%>
                    <%--<pe:permission key="add">--%>
                    <%--<a class="btn btn-success"--%>
                    <%--href="${BasePath}/order/product/toAdd?${PublicParams}">新增--%>
                    <%--</a>--%>
                    <%--</pe:permission>--%>
                    <%--</div>--%>
                    <div class="search-form fr cf">
                        <form id="myForm" name="myForm" action="${BasePath}/order/order/list?${PublicParams}" method="post">
                            订单号：<input type="text" class="txt100" name="orderNo" value="${orderNo }"/>
                            手机号：<input type="text" class="txt100" name="mobile" value="${mobile }"/>
                            卡号：<input type="text" class="txt100" name="cardNumber" value="${cardNumber }"/>
                            购买人：<input type="text" class="txt100" name="buyUser" value="${buyUser }"/>
                            使用人：<input type="text" class="txt100" name="endUser" value="${endUser }"/>
                            有效期：<input type="text" class="txt100" id="startDate" name="startDate" value="${startDate}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'endDate\')}',readOnly:'false'})"/>
                            至
                            <input type="text" class="txt100" id="endDate" name="endDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startDate\')}',readOnly:'false'})"/>

                            团单：<select name="groupOrderId" id="groupOrderId">
                            <option value="-1">请选择...</option>
                            <c:forEach items="${groupOrderList}" var="groupOrder">
                                <option value="${groupOrder.id}"
                                        <c:if test="${groupOrderId==groupOrder.id}">selected</c:if>   >${groupOrder.groupName}</option>
                            </c:forEach>
                        </select>
                            <script language="javascript">showQueryBox("groupOrderId", "");</script>
                            <input type="submit" value="查询" class="btn btn-success " style="margin-top: -10px"/>
                            <input type="hidden" name="start" id="start" value="${start }"/>
                            <input type="hidden" name="limit" id="limit" value="${limit }"/>
                        </form>
                    </div>
                </div>
            </div>
            <div class="data-table">
                <div class="table-striped">
                    <table cellspacing="1">
                        <thead>
                        <tr>
                            <th class="row-selected row-selected">
                                <input type="checkbox" id="checkAll" class="check-all regular-checkbox"><label for="checkAll"></label>
                            </th>
                            <%--<th>ID</th>--%>
                            <th>预约</th>
                            <th>订单号</th>
                            <th>有效期</th>
                            <th>来源</th>
                            <th>购买人</th>
                            <th>使用人</th>
                            <th>性别</th>
                            <th>年龄</th>
                            <th>手机</th>
                            <th>机构名称</th>
                            <th>产品名称</th>
                            <th>成交价</th>
                            <th>卡号</th>
                            <th>密码</th>
                            <th>备注</th>
                            <th>付款状态</th>
                            <th>付款给机构</th>
                            <th>到检</th>
                            <th>报告</th>
                            <th>报告领取方式</th>
                            <th>订单时间</th>
                            <%--<th>状态</th>--%>
                            <%--<th>操作</th>--%>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${list}" var="bean">
                            <tr ondblclick="orderDetail(${bean.id})">
                                <td><input type="checkbox" id="check_${bean.id}" name="ids[]" value="${bean.id}" class="ids regular-checkbox"><label for="check_${bean.id}"></label></td>
                                    <%--<td class="id">${bean.id}</td>--%>
                                <td>
                                    <c:if test="${bean.expired == 'Y'}">
                                        <font color="red">过期</font>
                                    </c:if>
                                    <c:if test="${bean.expired == 'N'}">
                                        <c:if test="${bean.bespeaked==1}">
                                            <a href="javascript:gaiyue(${bean.id})"><span style="color: #0000ff">改约</span></a>
                                        </c:if>
                                        <c:if test="${bean.bespeaked==0}">
                                            <a href="javascript:yuyue(${bean.id})">预约</a>
                                        </c:if>
                                    </c:if>
                                </td>
                                <td>${bean.orderNo}</td>
                                <td>${bean.startDateStr}
                                    至
                                    <br>
                                        ${bean.endDateStr}</td>
                                <td>${bean.groupName}</td>
                                <td>${bean.buyUser}</td>
                                <td>${bean.endUser}</td>
                                <td>${bean.sex}</td>
                                <td>${bean.age}</td>
                                <td>${bean.mobile}</td>
                                <td>${bean.institutionName}</td>
                                <td>${bean.productName}</td>
                                <td>${bean.salePrice}</td>
                                <td>${bean.cardNumber}</td>
                                <td>${bean.cardPassword}</td>
                                <td>${bean.comment}</td>
                                <td>${bean.payStatus}</td>
                                <td>${bean.paidToInstitution}</td>
                                <td>
                                    <c:choose>
                                        <c:when test="${bean.isChecked==1}">
                                            <font color=green>已到检</font>
                                        </c:when>
                                        <c:otherwise>
                                            <font color=red>未到检</font>
                                        </c:otherwise>
                                    </c:choose>

                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${bean.reportStatus==1}">
                                            <font color=green>已回</font>
                                        </c:when>
                                        <c:otherwise>
                                            <font color=red>未回</font>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>${bean.reportType}</td>
                                <td><script>formatTime(${bean.orderTime});</script></td>
                                    <%--<td></td>--%>
                                    <%--<td>--%>
                                    <%--&lt;%&ndash;<pe:permission key="update">&ndash;%&gt;--%>
                                    <%--<a href="${BasePath}/order/order/toAdd?id=${bean.id}&${PublicParams}">修改</a>--%>
                                    <%--&lt;%&ndash;</pe:permission>&ndash;%&gt;--%>
                                    <%--<br>--%>
                                    <%--&lt;%&ndash;<pe:permission key="delete">&ndash;%&gt;--%>
                                    <%--<a class="confirm ajax-get" href="${BasePath}/order/order/del?id=${bean.id}&${PublicParams}">删除</a>--%>
                                    <%--&lt;%&ndash;</pe:permission>&ndash;%&gt;--%>
                                    <%--</td>--%>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                    <div class="page" id="pager"></div>
                    <script type="text/javascript">
                        var sign = 0;
                        window.onload = function () {
                            PAGER.initPager('${start}', '${total}', '${limit}', 8, 'pager', getData);
                        }
                        function getData(currentPage, pageSize) {
                            if (sign > 0) {
                                $("#start").val(currentPage);
                                $("#limit").val(pageSize);
                                $("#myForm").submit();
                            }
                            sign = 1;
                        }
                    </script>
                </div>
            </div>
        </section>
    </div>
</div>
<jsp:include page="../../include/bottom.jsp"/>
<script>
    //详情页面
    function orderDetail(id) {
        layer.open({
            type: 2,
            offset: '100px',
            area: ['800px', '800px'],
            fix: false, //不固定
            maxmin: true,
            content: '${BasePath}/order/order/getOrderDetail?id=' + id
        });
    }

    function yuyue(id) {
        window.open('${BasePath}/order/order/toBespeak?yueType=1&id=' + id, "预约");
        /*layer.open({
            type: 2,
            offset: '100px',
            area: ['800px', '800px'],
            fix: false, //不固定
            maxmin: true,
            content: '${BasePath}/order/order/toBespeak?yueType=1&id=' + id
        });*/
    }
    function gaiyue(id) {
        window.open('${BasePath}/order/order/toBespeak?yueType=2&id=' + id, "改约");
        /*layer.open({
            type: 2,
            offset: '100px',
            area: ['800px', '800px'],
            fix: false, //不固定
            maxmin: true,
            content: '${BasePath}/order/order/toBespeak?yueType=2&id=' + id
        });*/
    }


    function toAdd() {
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        //新增
        if (idArray.length == 0) {
            window.location.href = " ${BasePath}/order/order/toAdd?${PublicParams}";
        } else if (idArray.length == 1) {
            window.location.href = " ${BasePath}/order/order/toAdd?${PublicParams}&id=" + idArray;
        } else {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        }
    }
    function multiDel() {
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        if (idArray.length == 0) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        } else {
            layer.msg('你确定要删除吗？', {
                time: 0 //不自动关闭
                , btn: ['确定', '取消']
                , yes: function (index) {
                    layer.close(index);
                    $.getJSON("${BasePath}/order/order/multiDel?ids="+idArray.toString(), function (data) {
                        if(data.errno==0){
                            layer.msg("操作成功！");
                            $("#myForm").submit();
                        }else{
                            layer.msg(data.errdesc, {icon: 5});
                        }
                    });
                }
            });
        }
    }

    function toExtend(){
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        if (idArray.length == 0) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        } else {
            layer.open({
                type: 2,
                offset: '100px',
                area: ['400px', '200px'],
                fix: false, //不固定
                maxmin: true,
                content: '${BasePath}/order/order/toExtendValidity?ids=' + idArray.join(",")
            });
        }
    }

    function printBarcode() {
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        if (idArray.length == 0) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        } else {
            layer.open({
                type: 2,
                offset: '100px',
                area: ['800px', '800px'],
                fix: false, //不固定
                maxmin: true,
                content: '${BasePath}/order/order/toPrintBarcode?ids=' + idArray.join(",")
            });
        }
    }
    function orderChecked(){
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        if (idArray.length == 0) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        } else {
            layer.msg('你确定操作吗？', {
                time: 0 //不自动关闭
                , btn: ['确定', '取消']
                , yes: function (index) {
                    layer.close(index);
                    $.getJSON("${BasePath}/order/order/changeStatus?ids="+idArray.toString()+"&field=isChecked&status=1", function (data) {
                        if(data.errno==0){
                            layer.msg("操作成功！");
                            $("#myForm").submit();
                        }else{
                            layer.msg(data.errdesc, {icon: 5});
                        }
                    });
                }
            });
        }
    }
    function orderReport(){
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        if (idArray.length == 0) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        } else {
            layer.msg('你确定操作吗？', {
                time: 0 //不自动关闭
                , btn: ['确定', '取消']
                , yes: function (index) {
                    layer.close(index);
                    $.getJSON("${BasePath}/order/order/changeStatus?ids="+idArray.toString()+"&field=reportStatus&status=1", function (data) {
                        if(data.errno==0){
                            layer.msg("操作成功！");
                            $("#myForm").submit();
                        }else{
                            layer.msg(data.errdesc, {icon: 5});
                        }
                    });
                }
            });
        }
    }
</script>